package com.hxs.hxsserver.controller.factor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxs.hxsserver.controller.BaseController;
import com.hxs.hxsserver.domain.dto.JsonResult;
import com.hxs.hxsserver.domain.dto.device.AlarmQueryDTO;
import com.hxs.hxsserver.domain.dto.device.AlarmRuleDTO;
import com.hxs.hxsserver.domain.dto.device.FactorDTO;
import com.hxs.hxsserver.domain.entity.device.AlarmLog;
import com.hxs.hxsserver.domain.entity.device.AlarmRule;
import com.hxs.hxsserver.service.AlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(value = "报警管理")
@RequestMapping("alarm")
public class AlarmController extends BaseController {
    @Resource
    private AlarmService alarmService;

    @PostMapping("/insertAlarmRule")
    @ApiOperation(value = "新增报警规则")
    public JsonResult<Boolean> insertAlarmRule(@RequestBody @Validated AlarmRuleDTO alarmRuleDTO){
        return JsonResult.success(alarmService.insertAlarmRule(alarmRuleDTO));
    }

    @PostMapping("/updateAlarmRule")
    @ApiOperation(value = "更新报警规则")
    public JsonResult<Boolean> updateAlarmRule(@RequestBody @Validated AlarmRuleDTO alarmRuleDTO){
        return JsonResult.success(alarmService.updateAlarmRule(alarmRuleDTO));
    }

    @PostMapping("/deleteAlarmRule")
    @ApiOperation(value = "删除报警规则")
    public JsonResult<Boolean> deleteAlarmRule(@RequestBody @Validated AlarmRuleDTO alarmRuleDTO){
        return JsonResult.success(alarmService.deleteAlarmRule(alarmRuleDTO));
    }

    @GetMapping("/getAlarmRuleList")
    @ApiOperation(value = "获取报警规则列表")
    public JsonResult<List<AlarmRule>> getAlarmRuleList(@Validated AlarmRuleDTO alarmRuleDTO){
        return JsonResult.success(alarmService.getAlarmRuleList(alarmRuleDTO));
    }

    @GetMapping("/getAlarmRuleById")
    @ApiOperation(value = "根据Id获取报警规则")
    public JsonResult<AlarmRule> getAlarmRuleById(@Validated Integer id){
        return JsonResult.success(alarmService.getAlarmRuleById(id));
    }

    @GetMapping("/getAlarmNewLog")
    @ApiOperation(value = "获取最新的一条报警记录")
    public JsonResult<AlarmLog> getAlarmNewLog(){
        return JsonResult.success(alarmService.getAlarmNewLog(getUser()));
    }

    @GetMapping("/getAlarmLog")
    @ApiOperation(value = "获取报警历史记录")
    public JsonResult<IPage<AlarmLog>> getAlarmLog(@RequestBody AlarmQueryDTO alarmQueryDTO){
        return JsonResult.success(alarmService.getAlarmLog(alarmQueryDTO,getUser()));
    }


}
